import com.baizhiedu.basic.mapper.OrdersMapper;
import com.baizhiedu.basic.pojo.Orders;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @Author: robert.song
 * @Date: Created in 2021/12/15
 */
@Slf4j
public class MybatisTestByAnnotations {

    @Test
    public void test() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfigAnnotation.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//        开启自动提交
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        findAll(sqlSession);

    }

    public void findAll(SqlSession sqlSession) {
        List<Orders> orders = sqlSession.getMapper(OrdersMapper.class).findAll();
        log.debug(orders.toString());
    }


}
